import logging
from redis import StrictRedis

class Config(object):
    # 项目配置
    DEBUG = True
    SECRET_KEY = "EjpNVSNQTyGi1VvWECj9TvC/+kq3oujee2kTfQUs8yCM6xX9Yjq52v54g+HVoknA"
    # 数据库配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:123456@127.0.0.1:3306/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True  # 配置数据库在函数执行后自动commit提交
    # redis配置
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    # session配置
    # 设置session存储类型为redis
    SESSION_TYPE = 'redis'
    # 配置session存储redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
    # 开启session签名
    SESSION_USE_SIGNER = True
    # 设置需要过期
    SESSION_PERMANENT = False
    # 设置过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2  # 两天

    # 设置日志等级 默认为debug
    LOG_LEVEL = logging.DEBUG

class DevelopmentConfig(Config):
    """开发环境配置"""
    DEBUG = True
    LOG_LEVEL = logging.DEBUG

class ProductionConfig(Config):
    """生产环境配置"""
    DEBUG = False
    LOG_LEVEL = logging.ERROR

class TestingConfig(Config):
    """测试环境配置"""
    DEBUG = True
    TESTING = True

config = {
    "development":DevelopmentConfig,
    "production":ProductionConfig,
    "testing":TestingConfig
}
